package zzps.exeed.kernel.awareness;

import zzps.exeed.kernel.core.PandaContainer;
import zzps.exeed.kernel.core.PandaEmbryo;
import zzps.exeed.kernel.event.EventBroadcaster;
import zzps.exeed.kernel.event.EventListener;
import zzps.exeed.kernel.holder.PandaHolder;

import java.util.function.Consumer;

public class EventListenerAwarenessProcessor implements AwarenessProcessor{
//    @Override
//    public void afterCollect(PandaEmbryo<?> pandaEmbryo, Consumer<PandaEmbryo<?>> consumer) {
//        Class<?> clazz = pandaEmbryo.clazz();
//        if (EventListener.class.isAssignableFrom(clazz)) {
//            consumer.accept(pandaEmbryo);
//        }
//    }

    @Override
    public <T> void beforeRegister(PandaHolder<T> pandaHolder, PandaContainer pandaContainer) {
    }

    @Override
    public <T> void afterRegister(PandaHolder<T> pandaHolder) {
        Class<?> clazz = pandaHolder.clazz();
        if (zzps.exeed.kernel.event.EventListener.class.isAssignableFrom(clazz)) {
            EventBroadcaster.subscribe((EventListener)pandaHolder.get());
        }
    }

//    @Override
    public <T> void beforeRegister(PandaHolder<T> pandaHolder) {
        Class<?> clazz = pandaHolder.clazz();
        if (EventListener.class.isAssignableFrom(clazz)) {
            EventBroadcaster.subscribe((EventListener)pandaHolder.get());
        }
    }
}
